home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6977 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: 20 Feb 96 23:33:40 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.824859220@rscernix>
  8. References: <Dn1C9z.DGv.0.net@indra.com> <1996Feb1922.17.19.879@koobera.math.uic.edu> <31298D20.41C6@bazis.nl>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <31298D20.41C6@bazis.nl> fkorntne@bazis.nl (Franz Korntner) writes:
  13.  
  14. >Steve Sullivan <sullivan@indra.com> wrote:
  15. >>    i = j + k;
  16. >>    if (overflowed) ....;
  17. >
  18. >Yes there is a method. 
  19. >
  20. >j+k will overflow when the result exceeds MAXINT
  21. >
  22. >Thus:  "if (j+k > MAXINT) overflow();" but the operation is undefined
  23. >if the result overflows, so the expression needs rewriting to make sure
  24. >this doesn't happen. The result is then "if (j>MAXINT-k) overflow();".
  25.  
  26. If k is negative, MAXINT-k will overflow :-)
  27.  
  28. BTW, MAXINT is spelled INT_MAX in C.
  29.  
  30. Dan
  31. --
  32. Dan Pop
  33. CERN, CN Division
  34. Email: danpop@mail.cern.ch 
  35. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  36.